<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet">
</head>
<body>
    <div class="long-form-wrap">
        <h1>注册页面</h1>
        <form class="longin-form" action="#" id="regist" method="get" autocomplete="off">
            <label>
                <input type="text" id="username" name="username" placeholder="username..." value="">
            </label>

            <label>
                <input type="text" id="password" name="password" placeholder="password..." value="">
            </label>
            <input type="submit" value="注册">
        </form>
    </div>
</body>
<script>
    //给表单绑定单击事件
    document.getElementById("regist").onsubmit=function(){
        //获取填写的账号密码
        let username = document.getElementById("username").value;
        let password = document.getElementById("password").value;

        //判断账号是否符合开头大写一共4-16位字母
        let reg1 = /^[A-Z][a-zA-Z]{4,15}$/;
        if(!reg1.test(username)){
            alert("用户名不符合规则,请开头大写,输入4到16位的纯字母!")
            return false;
        }

        //判断密码是否符合纯数字 6-10位
        let reg2 = /^[\d]{6,10}$/;
        if(!reg2.test(password)){
            alert("密码不符合规则,请输入6位纯数字密码")
            return false;
        }

        //所有条件都满足就提交表单
        return true;
    }
</script>
</html>